package com.fenye.testflow.controller;



import com.fenye.testflow.model.common.Result;
import com.fenye.testflow.model.common.ResultCodeEnum;
import com.fenye.testflow.model.dto.SysRoleDto;
import com.fenye.testflow.model.entity.system.SysRole;
import com.fenye.testflow.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/system/sysRole")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<SysRole> findByPage (
             SysRoleDto sysRoleDto,
            @PathVariable("pageNum") Long pageNum,
            @PathVariable("pageSize") Long pageSize){
        return sysRoleService.findPage(pageNum,pageSize,sysRoleDto);

    }

    @PostMapping("save")
    public Result saveSysRole(@RequestBody SysRole sysRole){
        sysRoleService.save(sysRole);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("updateById")
    public Result updateById(@RequestBody SysRole sysRole){
        sysRoleService.updateById(sysRole);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("delete/{id}")
    public Result deleteById(@PathVariable Long id){
        sysRoleService.removeById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("findAllRoles")
    public Result<Map<String, Object>> findAllRoles(){
            //map中有两组数组，1. 全部的角色列表 2. 已选中的角色列表
        Map<String,Object> roleMap = sysRoleService.findAllRoles();
        return Result.build(roleMap, ResultCodeEnum.SUCCESS);
    }
}
